package cc.dd.marketing.activity.rule.checker;


import cc.dd.marketing.activity.rule.domain.EndTimeRule;
import cc.dd.marketing.activity.dto.PullPInnerDTO;
import cc.dd.marketing.rule.base.RuleChecker;
import cc.dd.marketing.system.exception.base.BusinessException;
import cc.dd.marketing.system.exception.response.ResultCodeEnum;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 活动结束时间规则
 *
 * @author dongsufeng
 * @date 2022/9/9 2:26 PM
 */
@Component
public class EndTimeRuleChecker implements RuleChecker<EndTimeRule, PullPInnerDTO> {

    @Override
    public Boolean validate(EndTimeRule rule, PullPInnerDTO request) {
        if (rule.getRule().before(new Date())) {
            throw new BusinessException(ResultCodeEnum.RULE_CHECK_FAIL.getCode(), "活动已过期");
        }
        return true;
    }
}
